package com.ruoyi.web.controller.face;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.product.domain.SecdriverProduct;
import com.ruoyi.product.domain.SecdriverProductType;
import com.ruoyi.product.service.ISecdriverProductService;
import com.ruoyi.product.service.ISecdriverProductTypeService;
import com.ruoyi.system.service.ISysConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前端请求统一接口
 * 
 * @author ruoyi
 */
@RestController
public class FaceController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(FaceController.class);

    @Autowired
    private ISysConfigService configService;

    @Autowired
    private ISecdriverProductService secdriverProductService;

    @Autowired
    private ISecdriverProductTypeService secdriverProductTypeService;



    /*--------------------------免登陆以face开头------------------------*/

    /**
     * 查询平台配置参数
     */
    @GetMapping("/face/system/config/list")
    public AjaxResult listPlatform()
    {
        Map<String,String> platformConfig = new HashMap<String,String>();
        String platformName = configService.selectConfigByKey("platform_name");
        String platformLogo = configService.selectConfigByKey("platform_logo");
        String platformCopyRight = configService.selectConfigByKey("platform_copy_right");
        platformConfig.put("platformName",platformName);
        platformConfig.put("platformLogo",platformLogo);
        platformConfig.put("platformCopyRight",platformCopyRight);
        return AjaxResult.success(platformConfig);
    }

    /**
     * 查询平台配置参数
     */
    @GetMapping("/face/product/list")
    public TableDataInfo list(SecdriverProduct secdriverProduct)
    {
        startPage();
        secdriverProduct.setStatus("0");
        List<SecdriverProduct> list = secdriverProductService.selectSecdriverProductList(secdriverProduct);
        //遍历拆分产品功能
        if(null!=list && list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                SecdriverProduct secdriverProduct1 =  list.get(i);
                if(StringUtils.isNotEmpty(secdriverProduct1.getProductFunction())){
                    String[] functionList = secdriverProduct1.getProductFunction().split(",");
                    secdriverProduct1.getParams().put("functionList",functionList);
                 }
            }
        }
        return getDataTable(list);
    }

    /**
     * 查询平台配置参数
     */
    @GetMapping("/face/productType/list")
    public AjaxResult listProductTypeList()
    {
        SecdriverProductType secdriverProductType = new SecdriverProductType();
        secdriverProductType.setStatus("0");
        List<SecdriverProductType> list = secdriverProductTypeService.selectSecdriverProductTypeList(secdriverProductType);
        return AjaxResult.success(list);
    }


}
